package GUI;

import java.util.ArrayList;
import java.util.ArrayList;


public class SeasonEpisodeInfoPanel {

	//static ArrayList<Character> characterSelected;
	//static ArrayList<CatchPhrase> catchPhrasesSelected;
	public int x;
	public int y;
	public int width;
	public int height;
	public ScrollBar scrollBar;
	ArrayList<SeasonEpisodeInfoPanelData> sd;


	public SeasonEpisodeInfoPanel(){
		x=Utils.globalProcessing.width-240;
		y=Utils.globalProcessing.height/2+15;
		width = 230;
		height = Utils.globalProcessing.height/2 -30;
		scrollBar = new ScrollBar();
		sd = new ArrayList<SeasonEpisodeInfoPanelData>();
		for(int i=0;i<Utils.seasons.size();i++){
			sd.add(new SeasonEpisodeInfoPanelData(Utils.seasons.get(i)));
		}
	}

	public void draw()
	{

		Utils.globalProcessing.fill(Utils.textColor);
		Utils.globalProcessing.textFont(Utils.plotFont, 15);
		Utils.globalProcessing.textAlign(Utils.globalProcessing.LEFT);
		Utils.globalProcessing.text("Seasons and Episodes", x , y + 10);
		
		int linesCount=0;
		for(int i=0;i<sd.size();i++){
			linesCount += (Utils.seip.sd.get(i).pmButton.pluState ? 0 :
				(Utils.seip.sd.get(i).sb.s.getEpisodes().size())) +1;
		}
		float lineVal;
		if(((linesCount)*25)>height){
			Utils.seip.scrollBar.width = 15;
			Utils.seip.scrollBar.x = Utils.width-15;
			Utils.seip.scrollBar.y = y+30;
			Utils.seip.scrollBar.height = Utils.globalProcessing.height/2 -50;
			Utils.seip.scrollBar.draw();  
			Utils.seip.scrollBar.size = 1/(float)(linesCount);
			lineVal = Main.map(Utils.seip.scrollBar.val,0,1,0,linesCount+1);

		}
		else lineVal =0;
		Integer[] minSeasonVal = new Integer[6];
		int count=0,j=0;
		for(int i=0;i<sd.size();i++){
			minSeasonVal[i]=count;
			count += (Utils.seip.sd.get(i).pmButton.pluState ? 0 :
				(Utils.seip.sd.get(i).sb.s.getEpisodes().size())) +1;
		}
		count=0;
		for(int i=0;i<sd.size();i++){
			count += (Utils.seip.sd.get(i).pmButton.pluState ? 0 :
				(Utils.seip.sd.get(i).sb.s.getEpisodes().size())) +1;
			if(count<=lineVal){
				j++;
			}
			else {
				count -= (Utils.seip.sd.get(i).pmButton.pluState ? 0 :(Utils.seip.sd.get(i).sb.s.getEpisodes().size())) +1;
				break;
			}
		}
		int k=0,tot=0;
		//draw season and episodes
		for(int i=j; i<Utils.seip.sd.size();i++){
			if(count==(int)lineVal || i>j ){
			PlusMinusButton pmb = Utils.seip.sd.get(i).pmButton;
			pmb.x=x;
			pmb.y=y+30+(tot)*25 +6;
			pmb.draw();
			SeasonButton sb = Utils.seip.sd.get(i).sb;
			sb.x=x+12;
			sb.y=y+30+(tot)*25;
			sb.width=100;
			sb.height=20;
			sb.draw();
			tot++;
			}

			if(!Utils.seip.sd.get(i).pmButton.pluState){
				//draw episodes	
				if(lineVal>minSeasonVal[i])
					for(k=(int)lineVal-count;k<Utils.seip.sd.get(i).ebs.size();k++){
						EpisodeButton eb = Utils.seip.sd.get(i).ebs.get(k);
						eb.x=x+25;
						eb.y=y+30+(tot)*25;
						eb.width=100;
						eb.height=20;
						eb.draw();
						tot++;
					}
				else
					for(k=0;k<Utils.seip.sd.get(i).ebs.size();k++){
						EpisodeButton eb = Utils.seip.sd.get(i).ebs.get(k);
						eb.x=x+25;
						eb.y=y+30+(tot)*25;
						eb.width=100;
						eb.height=20;
						eb.draw();
						tot++;
					}
				
			}
		}

	}


}
